//
//  ChooseHeTongCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/2.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "ChooseHeTongCell.h"
#import "HeTongMainModel.h"

@interface ChooseHeTongCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UIButton *fuZhiBtn;
@property (nonatomic, strong) UIImageView *logoImgView;
@property (nonatomic, strong) UILabel *companyTitleLab;
@property (nonatomic, strong) UILabel *companyLab;
@property (nonatomic, strong) UILabel *dateTitleLab;
@property (nonatomic, strong) UILabel *dateLab;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) UIImageView *arrowImgView;
@property (nonatomic, strong) UILabel *arrowLab;

@end

@implementation ChooseHeTongCell

+ (instancetype)ChooseHeTongCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"ChooseHeTongCell";
    ChooseHeTongCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ChooseHeTongCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 165)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        self.noTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.noLab];
        
        self.fuZhiBtn = [UIButton new];
        [self.bgView addSubview:self.fuZhiBtn];
        
        self.logoImgView = [UIImageView new];
        [self.logoImgView setImage:[UIImage imageNamed:@"icon_pdf"]];
        [self.bgView addSubview:self.logoImgView];
        
        self.companyTitleLab = [UILabel new];
        self.companyTitleLab.textColor = HexColor(0x9C9DB3);
        self.companyTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.companyTitleLab];
        
        self.companyLab = [UILabel new];
        self.companyLab.textColor = HexColor(0x2B2C44);
        self.companyLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.companyLab];
        
        self.dateTitleLab = [UILabel new];
        self.dateTitleLab.textColor = HexColor(0x9C9DB3);
        self.dateTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.dateTitleLab];
        
        self.dateLab = [UILabel new];
        self.dateLab.textColor = HexColor(0x2B2C44);
        self.dateLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.dateLab];
        
        self.line = [UILabel new];
        self.line.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line];
        
        self.arrowImgView = [UIImageView new];
        [self.arrowImgView setImage:[UIImage imageNamed:@"icon_checklistv"]];
        [self.bgView addSubview:self.arrowImgView];
        
        self.arrowLab = [UILabel new];
        self.arrowLab.textColor = Color_ThemeColor;
        self.arrowLab.font = BoldFontOfSize(16);
        self.arrowLab.text = @"选择合同";
        [self.bgView addSubview:self.arrowLab];
        
        self.selectBtn = [UIButton new];
        [self.selectBtn addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)selectClick {
    if (self.selectBlock) {
        self.selectBlock();
    }
}

-(void)setModel:(HeTongMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.noTitleLab.text = @"流水号：";
    self.noTitleLab.nim_left = 10;
    self.noTitleLab.nim_top = 15;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.constract_sn;
    self.noLab.nim_left = self.noTitleLab.nim_right;
    [self.noLab sizeToFit];
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.fuZhiBtn.nim_left = self.noLab.nim_right + 6;
    self.fuZhiBtn.nim_width = 18;
    self.fuZhiBtn.nim_height = 18;
    self.fuZhiBtn.nim_centerY = self.noLab.nim_centerY;
    [self.fuZhiBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
    
    self.line.frame = CGRectMake(0, 112, self.bgView.nim_width, 1);
    
    self.selectBtn.frame = CGRectMake(0, self.line.nim_bottom, self.bgView.nim_width, self.bgView.nim_height - self.line.nim_top);
    
    self.arrowImgView.nim_width = 18;
    self.arrowImgView.nim_height = 18;
    self.arrowImgView.nim_centerY = self.selectBtn.nim_centerY;
    
    [self.arrowLab sizeToFit];
    self.arrowLab.nim_centerY = self.selectBtn.nim_centerY;
    
    self.arrowImgView.nim_left = (self.bgView.nim_width - 10 - self.arrowImgView.nim_width - self.arrowLab.nim_width) * 0.5;
    self.arrowLab.nim_left = self.arrowImgView.nim_right + 10;
    
    self.logoImgView.nim_width = 30;
    self.logoImgView.nim_height = 40;
    self.logoImgView.nim_left = 20;
    self.logoImgView.nim_top = self.fuZhiBtn.nim_bottom + (self.line.nim_top - self.fuZhiBtn.nim_bottom - self.logoImgView.nim_height) * 0.5;
    
    self.companyTitleLab.text = @"承运方：";
    [self.companyTitleLab sizeToFit];
    self.companyTitleLab.nim_left = self.logoImgView.nim_right + 20;
    self.companyTitleLab.nim_top = self.logoImgView.nim_top;
    
    self.companyLab.nim_left = self.companyTitleLab.nim_right;
    self.companyLab.nim_top = self.companyTitleLab.nim_top;
    self.companyLab.text = self.model.name;
    [self.companyLab sizeToFit];
    self.companyLab.nim_width = self.bgView.nim_width - 10 - self.companyLab.nim_left;
    
    self.dateTitleLab.text = @"有效期：";
    [self.dateTitleLab sizeToFit];
    self.dateTitleLab.nim_left = self.logoImgView.nim_right + 20;
    self.dateTitleLab.nim_top = self.logoImgView.nim_bottom - self.dateTitleLab.nim_height;
    
    self.dateLab.nim_left = self.dateTitleLab.nim_right;
    self.dateLab.nim_top = self.dateTitleLab.nim_top;
    self.dateLab.text = [NSString stringWithFormat:@"%@ - %@",self.model.startTime,self.model.endTime];
    [self.dateLab sizeToFit];
    self.dateLab.nim_width = self.bgView.nim_width - 10 - self.dateTitleLab.nim_left;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
